package com.zbfmq.xonfig;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/11  8:31
 * 描述:
 */
@Configuration
public class RabbitMqConfig2 {

    @Bean("queue3")
    public Queue getQueue(){

        Map<String,Object> map=new HashMap<>();
        //map.put("x-message-ttl",5000);
        map.put("x-dead-letter-exchange","dead-exhange");
        map.put("x-dead-letter-routing-key","dead-key");
        Queue queue = new Queue("zhengchang-queue", false, false, true, map);
        return queue;
    }

   @Bean("exchange3")
   public Exchange getExchange3(){

       //Exchange build = ExchangeBuilder.directExchange("ZHI-LIAN-1").durable(false).autoDelete().build();

       //演示 队列消息接收确认 returnCallback 接口
       Exchange build = ExchangeBuilder.directExchange("ZHI-LIAN-1").durable(true).build();

       return build;
   }


    @Bean("binding3")
    public Binding getHeaderBinding(@Qualifier("queue3") Queue queue, @Qualifier("exchange3") Exchange exchange){

        Binding binding = BindingBuilder.bind(queue).to(exchange).with("zhengchang-key").noargs();

        return binding;
    }


    /**
     * 作者: LCG
     * 日期: 2021/3/11  9:11
     * 描述: 演示死信队列
     * @Param []
     * @Return org.springframework.amqp.core.Queue
     */
    @Bean("queue4")
    public Queue getDeadQueue(){
        Queue queue = new Queue("dead-queue", false, false, true);
        return queue;
    }
    @Bean("deadExchange")
    public Exchange getDeadExchange(){
        Exchange build = ExchangeBuilder.directExchange("dead-exhange").durable(false).autoDelete().build();
        return build;
    }
    @Bean("deadBinding")
    public Binding getDeadBinding(@Qualifier("queue4") Queue queue, @Qualifier("deadExchange") Exchange exchange){

        Binding binding = BindingBuilder.bind(queue).to(exchange).with("dead-key").noargs();

        return binding;
    }


}
